//
//  NSString+MD5.m
//  FMDownLoad
//
//  Created by apple on 17/3/22.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (MD5)

- (NSString *)md5Str{
    
    const char *data = [self UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];

    //第一个参数 传字符串 第二个参数传字符串长度 第三个是结果
    CC_MD5(data, (CC_LONG)strlen(data) , result);
    NSMutableString *results = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [results appendFormat:@"%02x", result[i]];
    }
    return results;
}

@end
